﻿using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

namespace Metro.Kashikoi.ServiceContract.Storage
{
    /// <summary>
    /// This class defines the weekly trigger.
    /// </summary>
    [DataContract(IsReference = true)]
    [Table("WeeklyTriggers")]
    public class WeeklyTrigger : AutoTrigger
    {
        /// <summary>
        /// Gets or sets the day code.
        /// </summary>
        /// <value>
        /// The day code.
        /// </value>
        [DataMember]
        [Range(1, 127)]
        [RangeValidator(1, RangeBoundaryType.Inclusive, 127, RangeBoundaryType.Inclusive)]
        public int DayCode { get; set; }

        /// <summary>
        /// Gets or sets the days.
        /// </summary>
        /// <value>
        /// The days.
        /// </value>
        public DaysOfWeek Days
        {
            get { return (DaysOfWeek)DayCode; }
            set { DayCode = (int)value; }
        }

        /// <summary>
        /// Copies the specified to the destination.
        /// </summary>
        /// <param name="destination">The destination.</param>
        public void CopyTo(WeeklyTrigger destination)
        {
            base.CopyTo(destination);
            destination.DayCode = this.DayCode;
        }

        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>
        /// Newly cloned instance.
        /// </returns>
        public override Trigger Clone()
        {
            var trigger = new WeeklyTrigger();
            this.CopyTo(trigger);
            return trigger;
        }
    }
}
